/* iPad和移动设备专用样式 */

/* 基础移动设备优化 */
.mobile-device {
    -webkit-touch-callout: none;
    -webkit-user-select: none;
    -khtml-user-select: none;
    -moz-user-select: none;
    -ms-user-select: none;
    user-select: none;
    -webkit-tap-highlight-color: transparent;
}

/* iPad专用优化 */
.ipad-device {
    /* 禁用Safari的弹性滚动 */
    -webkit-overflow-scrolling: touch;
}

/* 触控区域优化 */
.mobile-device .control-button {
    min-height: 44px; /* Apple推荐的最小触控区域 */
    font-size: 18px;
    padding: 15px 20px;
    margin-bottom: 15px;
}

.mobile-device .slider {
    height: 10px; /* 增加滑块高度便于触控 */
}

.mobile-device .slider::-webkit-slider-thumb {
    width: 24px;
    height: 24px;
}

/* Canvas触控优化 */
.mobile-device #sandbox-canvas {
    touch-action: none; /* 禁用默认触控行为 */
    -webkit-touch-callout: none;
    -webkit-user-select: none;
}

/* 状态指示器在移动设备上更大 */
.mobile-device .status-indicator {
    width: 16px;
    height: 16px;
}

/* 移动设备上的工具栏优化 */
@media (max-width: 1024px) {
    .mobile-device .header {
        position: sticky;
        top: 0;
        z-index: 100;
    }
    
    .mobile-device .control-panel {
        background: rgba(255, 255, 255, 0.15);
        backdrop-filter: blur(15px);
        border-radius: 20px;
        padding: 25px;
        margin-bottom: 15px;
    }
    
    .mobile-device .control-section {
        margin-bottom: 20px;
    }
    
    .mobile-device .control-section h3 {
        font-size: 20px;
        margin-bottom: 18px;
    }
}

/* iPad横屏优化 */
@media (orientation: landscape) and (max-width: 1024px) {
    .ipad-device .main-content {
        flex-direction: row;
        gap: 20px;
    }
    
    .ipad-device .control-panel {
        width: 280px;
        order: 0;
    }
    
    .ipad-device .control-section {
        width: 100%;
        margin-right: 0;
    }
}

/* iPad竖屏优化 */
@media (orientation: portrait) and (max-width: 1024px) {
    .ipad-device .control-panel {
        order: -1;
    }
    
    .ipad-device .control-section {
        display: inline-block;
        width: 48%;
        margin-right: 2%;
        vertical-align: top;
    }
    
    .ipad-device .control-section:nth-child(even) {
        margin-right: 0;
    }
}

/* 手机竖屏优化 */
@media (max-width: 768px) {
    .mobile-device .title {
        font-size: 16px;
    }
    
    .mobile-device .control-section {
        width: 100% !important;
        margin-right: 0 !important;
        display: block;
    }
    
    .mobile-device .main-content {
        padding: 10px;
        gap: 10px;
    }
    
    .mobile-device .control-panel {
        padding: 15px;
    }
    
    .mobile-device .coordinates {
        font-size: 12px;
    }
}

/* 触控反馈动画 */
.mobile-device .control-button:active {
    transform: scale(0.95);
    background: rgba(255, 255, 255, 0.4);
    transition: all 0.1s ease;
}

.mobile-device .slider:active {
    transform: scale(1.05);
    transition: transform 0.1s ease;
}

/* 虚拟键盘适配 */
@media (max-height: 500px) {
    .mobile-device .header {
        padding: 8px 15px;
    }
    
    .mobile-device .title {
        font-size: 14px;
    }
    
    .mobile-device .control-panel {
        padding: 10px;
    }
    
    .mobile-device .control-button {
        padding: 8px 12px;
        font-size: 14px;
        min-height: 36px;
    }
}

/* 高DPI屏幕优化 */
@media (-webkit-min-device-pixel-ratio: 2), (min-resolution: 192dpi) {
    .mobile-device #sandbox-canvas {
        /* Canvas高DPI优化将在JavaScript中处理 */
    }
}

/* 深色模式支持 */
@media (prefers-color-scheme: dark) {
    .mobile-device {
        background: #1a1a1a;
        color: #ffffff;
    }
    
    .mobile-device .control-panel {
        background: rgba(40, 40, 40, 0.95);
        border-color: #444;
    }
    
    .mobile-device .sandbox-canvas {
        border-color: #444;
    }
    
    .mobile-device button {
        background: #333;
        color: #fff;
        border-color: #555;
    }
    
    .mobile-device button:hover {
        background: #444;
    }
    
    .mobile-device input[type="range"] {
        background: #333;
    }
    
    .gesture-hint {
        background: rgba(40, 40, 40, 0.9);
    }
    
    .fullscreen-exit {
        background: rgba(40, 40, 40, 0.8);
    }
    
    .fullscreen-exit:hover {
        background: rgba(60, 60, 60, 0.9);
    }
}

/* 高对比度模式支持 */
@media (prefers-contrast: high) {
    .mobile-device button {
        border: 2px solid currentColor;
        font-weight: bold;
    }
    
    .mobile-device .sandbox-canvas {
        border: 3px solid currentColor;
    }
    
    .gesture-hint,
    .multitouch-support {
        border: 2px solid white;
        font-weight: bold;
    }
}

/* 大字体支持 */
@media (prefers-reduced-motion: no-preference) {
    .mobile-device button:active {
        animation: pulse 0.1s ease-out;
    }
}

/* 屏幕方向数据属性样式 */
body[data-orientation="0"] .quick-actions {
    /* 竖屏模式 */
    flex-direction: column;
    width: 100%;
    bottom: 0;
    left: 0;
    right: 0;
}

body[data-orientation="90"],
body[data-orientation="-90"] {
    /* 横屏模式 */
}

body[data-orientation="90"] .quick-actions,
body[data-orientation="-90"] .quick-actions {
    flex-direction: row;
    right: 10px;
    bottom: 50%;
    transform: translateY(50%);
    width: auto;
}

/* 性能优化 */
.mobile-device * {
    will-change: auto;
}

.mobile-device canvas {
    will-change: transform;
}

.mobile-device .control-panel {
    will-change: transform, opacity;
}

/* 触摸目标大小优化 */
@media (pointer: coarse) {
    .mobile-device button,
    .mobile-device input[type="range"] {
        min-height: 48px;
        min-width: 48px;
    }
    
    .mobile-device .quick-actions button {
        min-height: 56px;
        min-width: 56px;
        font-size: 16px;
    }
}

/* 手势提示样式 */
.gesture-hint {
    position: fixed;
    bottom: 100px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 12px 20px;
    border-radius: 25px;
    font-size: 14px;
    z-index: 1000;
    animation: fadeInUp 0.5s ease-out;
    pointer-events: none;
}

.multitouch-support {
    position: absolute;
    top: 10px;
    left: 10px;
    background: rgba(52, 152, 219, 0.9);
    color: white;
    padding: 8px 15px;
    border-radius: 20px;
    font-size: 12px;
    z-index: 100;
    animation: fadeInDown 0.5s ease-out;
    pointer-events: none;
}

/* 动画定义 */
@keyframes fadeInUp {
    from {
        opacity: 0;
        transform: translateX(-50%) translateY(20px);
    }
    to {
        opacity: 1;
        transform: translateX(-50%) translateY(0);
    }
}

@keyframes fadeInDown {
    from {
        opacity: 0;
        transform: translateY(-20px);
    }
    to {
        opacity: 1;
        transform: translateY(0);
    }
}

@keyframes slideIn {
    from {
        opacity: 0;
        transform: translateX(100%);
    }
    to {
        opacity: 1;
        transform: translateX(0);
    }
}

@keyframes slideOut {
    from {
        opacity: 1;
        transform: translateX(0);
    }
    to {
        opacity: 0;
        transform: translateX(100%);
    }
}

@keyframes pulse {
    0%, 100% {
        transform: scale(1);
    }
    50% {
        transform: scale(1.05);
    }
}

/* 触摸反馈动画 */
.touch-feedback {
    animation: pulse 0.2s ease-out;
}

/* 无障碍访问优化 */
@media (prefers-reduced-motion: reduce) {
    * {
        animation-duration: 0.01ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: 0.01ms !important;
    }
    
    .gesture-hint,
    .multitouch-support {
        animation: none;
    }
}

/* 焦点可见性 */
.mobile-device .control-button:focus {
    outline: 3px solid #3498db;
    outline-offset: 2px;
}

.mobile-device .slider:focus {
    outline: 2px solid #3498db;
    outline-offset: 1px;
}

/* 手势提示 */
.gesture-hint {
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    background: rgba(0, 0, 0, 0.8);
    color: white;
    padding: 15px 25px;
    border-radius: 25px;
    font-size: 16px;
    z-index: 1000;
    animation: fadeInOut 3s ease-in-out;
    pointer-events: none;
}

@keyframes fadeInOut {
    0%, 100% { opacity: 0; }
    20%, 80% { opacity: 1; }
}

/* 连接状态在移动设备上的优化显示 */
.mobile-device .status {
    font-size: 14px;
}

.mobile-device .status-text {
    display: none; /* 在小屏幕上隐藏文字，只显示指示器 */
}

@media (min-width: 768px) {
    .mobile-device .status-text {
        display: inline;
    }
}

/* 全屏模式样式 */
.fullscreen-canvas {
    position: fixed !important;
    top: 0 !important;
    left: 0 !important;
    width: 100vw !important;
    height: 100vh !important;
    z-index: 9999 !important;
    background: #000;
}

.fullscreen-canvas canvas {
    width: 100% !important;
    height: 100% !important;
}

/* 全屏退出按钮 */
.fullscreen-exit {
    position: fixed;
    top: 20px;
    right: 20px;
    width: 50px;
    height: 50px;
    background: rgba(0, 0, 0, 0.7);
    color: white;
    border: none;
    border-radius: 50%;
    font-size: 24px;
    font-weight: bold;
    cursor: pointer;
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    transition: all 0.3s ease;
}

.fullscreen-exit:hover {
    background: rgba(0, 0, 0, 0.9);
    transform: scale(1.1);
}

.fullscreen-exit:active {
    transform: scale(0.95);
}

/* 多点触控支持提示 */
.multitouch-support {
    position: absolute;
    bottom: 20px;
    left: 50%;
    transform: translateX(-50%);
    background: rgba(52, 152, 219, 0.9);
    color: white;
    padding: 8px 15px;
    border-radius: 15px;
    font-size: 12px;
    z-index: 100;
    animation: slideUp 0.5s ease-out;
}

@keyframes slideUp {
    from {
        transform: translate(-50%, 100%);
        opacity: 0;
    }
    to {
        transform: translate(-50%, 0);
        opacity: 1;
    }
}